/**
 * Created by Alex on 16/12/31.
 */
'use strict'

const mongoose = require('mongoose')
const Restaurant = mongoose.model('Restaurant')
const Interesting = mongoose.model('Interesting')

const userPermission = {
  DEFAULT: {
    visit: ['1', '2', '21', '7', '5', '51', '52', '53'],
    role: 'DEFAULT',
  },
  ADMIN: {
    role: 'ADMIN',
  },
  DEVELOPER: {
    role: 'DEVELOPER',
  },
}

exports.login = function* (next) {
  const user =  {
    id: 0,
    username: 'admin',
    password: 'admin',
    permissions: userPermission.ADMIN,
  }
  const now = new Date()
  now.setDate(now.getDate() + 1)
  this.cookies.set('token', JSON.stringify({ id: user.id, deadline: now.getTime() }), {
    maxAge: 900000,
    httpOnly: true,
  })
  this.body = {"success":true,"message":"Ok"}
}

exports.logout = function* (next) {
  this.body = {"success":true,"message":"Ok"}
}


exports.user = function* (next) {
  this.body = {"success":true,"user":{"permissions":{"role":"admin"},"username":"admin","id":0}}
}

exports.menu = function* (next) {
  this.body = [{"id": "0", "name": "泰土著", "icon": "camera-o", "route": "/tai"}]
}